
<template>
  <div>
    <h2>儿子:{{ count }}</h2>
    <p>
      <button @click="emit('change-count', Math.random())">修改父count</button>
    </p>
  </div>
</template>

<script setup>
// 1. 接收父组件数据
// eslint-disable-next-line no-undef
defineProps({
  count: {
    type: Number,
    default: 0
  }
})
// 2. 定义自定义事件
// emit 等价于 this.$emit
// eslint-disable-next-line no-undef
const emit = defineEmits(['change-count'])

const childFn = () => {
  console.log('son')
}
// 对外暴露属性或方法
// eslint-disable-next-line no-undef
defineExpose({
  childFn,
  test: 123
})

</script>

<style lang="scss" scoped>
</style>
